/*
 * Midlet.java
 */

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;

import org.ksoap.SoapObject;
import org.ksoap.transport.HttpTransport;

/**
 *
 * @author  Alexander De Luca
 * @version 1.0
 */
public class Midlet extends MIDlet implements CommandListener {
    private static Command CLOSE_COMMAND = new Command("close", Command.EXIT, 1);
    private Form helloForm;
    private StringItem text;
    private Display display;

    private void createForm() {
        display = Display.getDisplay(this);
        helloForm = new Form("Hello World");
        helloForm.addCommand(CLOSE_COMMAND);
        helloForm.setCommandListener(this);
        text = new StringItem(null, "Hello World");
        
//        List list = new List("Escolha", Choice.EXCLUSIVE);
//        list.append("Buy", null);
//        list.append("Sell", null);
//        list.setTicker(new Ticker("Escolha"));
//        helloForm..append(list);
//        display.setCurrent(list);
        StringBuffer stringBuffer = new StringBuffer(); 
        
        TextBox textBox = null; 
        
        // Chama o WebService
//        SoapObject client = new  SoapObject(url,"soma"); 
//        client.addProperty("valor1",new Integer(2)); 
//        client.addProperty("valor2",new Integer(4)); 
//        HttpTransport ht = new HttpTransport(url,"soma");
//        stringBuffer.append("Resultado: " + ht.call(client));
        
        // mostra o valor do resultado na tela.
        textBox = new TextBox("Teste WebService", stringBuffer.toString(), 1024, 0); 
        display.setCurrent(textBox); 
        
        
        helloForm.append(text);
        display.setCurrent(helloForm);
    }

    public void commandAction(Command comm, Displayable disp) {
        if(comm == CLOSE_COMMAND)
            this.exitMIDlet();
    }

    public void exitMIDlet() {
        display.setCurrent(null);
        destroyApp(true);
        notifyDestroyed();
    }

    public void startApp() {
        this.createForm();
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
}